home *** CD-ROM | disk | FTP | other *** search
/ Cream of the Crop 1 / Cream of the Crop 1.iso / PROGRAM / DDJ0992.ARJ / SETPIXEL.ASM < prev    next >
Assembly Source File  |  1992-06-08  |  2KB  |  54 lines

  1. ; Mode X (320x240, 256 colors) write pixel routine. Works on all VGAs.
  2. ; No clipping is performed.
  3. ; C near-callable as:
  4. ;    void WritePixelX(int X, int Y, int Color);
  5.  
  6. SC_INDEX equ    03c4h   ;Sequence Controller Index
  7. MAP_MASK equ    02h     ;index in SC of Map Mask register
  8. SCREEN_SEG equ  0a000h  ;segment of display memory in mode X
  9. SCREEN_WIDTH equ 80     ;width of screen in bytes from one scan line
  10.                         ; to the next
  11.  
  12. parms   struc
  13.         dw      2 dup (?) ;pushed BP and return address
  14. X       dw      ?       ;X coordinate of pixel to draw
  15. Y       dw      ?       ;Y coordinate of pixel to draw
  16. Color   dw      ?       ;color in which to draw pixel
  17. parms   ends
  18.  
  19.         .model  small
  20.  
  21.         .data
  22.         extrn _CurrentPageBase:word
  23.  
  24.         .code
  25.         public  _WritePixelX
  26. _WritePixelX    proc    near
  27.         push    bp      ;preserve caller's stack frame
  28.         mov     bp,sp   ;point to local stack frame
  29.  
  30.         mov     ax,SCREEN_WIDTH
  31.         mul     [bp+Y]  ;offset of pixel's scan line in page
  32.         mov     bx,[bp+X]
  33.         shr     bx,1
  34.         shr     bx,1    ;X/4 = offset of pixel in scan line
  35.         add     bx,ax   ;offset of pixel in page
  36.         add     bx,[_CurrentPageBase] ;offset of pixel in display memory
  37.         mov     ax,SCREEN_SEG
  38.         mov     es,ax   ;point ES:BX to the pixel's address
  39.  
  40.         mov     cl,byte ptr [bp+X]
  41.         and     cl,011b ;CL = pixel's plane
  42.         mov     ax,0100h + MAP_MASK ;AL = index in SC of Map Mask reg
  43.         shl     ah,cl   ;set only the bit for the pixel's plane to 1
  44.         mov     dx,SC_INDEX ;set the Map Mask to enable only the
  45.         out     dx,ax       ; pixel's plane
  46.  
  47.         mov     al,byte ptr [bp+Color]
  48.         mov     es:[bx],al ;draw the pixel in the desired color
  49.  
  50.         pop     bp      ;restore caller's stack frame
  51.         ret
  52. _WritePixelX    endp
  53.         end
  54.